package com.hongdee.crm.statistics.task.dao.impl;

import com.hongdee.base.basedao.impl.BaseDaoImpl;
import com.hongdee.crm.statistics.task.dao.ITCrmCarCountTaskDao;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by My on 2017/5/24.
 */
@Component
public class TCrmCarCountTaskDaoImpl extends BaseDaoImpl implements ITCrmCarCountTaskDao {

    /**
     * 查询工单中有多少公司 依照公司来生成
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryCompanyByWorkOrder(String tabName) throws Exception {
        String sql="select company_id from "+tabName+" GROUP BY company_id";
        return this.getJdbcDao().queryForMapListBySql(sql);
    }

    @Override
    public Map<String, Object> queryAccidentCarInfo(String companyId, String year, String label) throws Exception {
        String sql="select * from T_CRM_KPI_SG where company_id=? and count_year=? and count_tag=? limit 0,1";
        return this.getJdbcDao().queryForMapBySqlWithParams(sql,companyId,year,label);
    }

    @Override
    public boolean queryStatisticsDataByCompany(String companyId,String tabName) throws Exception {
        String sql="select * from "+tabName+" where company_id=? ";
        List list=this.getJdbcDao().queryForMapListBySqlWithParams(sql,companyId);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    @Override
    public Map<String, Object> queryAccidentCarInfo(String companyId,String uid, String year, String label,String tabName) throws Exception {
        String sql="select * from "+tabName+" where company_id=? and sa_id=? and count_year=? and count_tag=? limit 0,1";
        return this.getJdbcDao().queryForMapBySqlWithParams(sql,companyId,uid,year,label);
    }

}
